package com.asia5b.a5mall.order.adapter

import android.view.View
import android.widget.ImageView
import com.asia5b.a5mall.middleware.model.order.LogisItemBean
import com.asia5b.a5mall.order.R
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * Created by zhangyuncai on 2020/5/26.
 */
class LogisItemAdapter(list: ArrayList<LogisItemBean>) :
        BaseQuickAdapter<LogisItemBean, BaseViewHolder>(R.layout.item_logisitem_adapter, list) {
    override fun convert(helper: BaseViewHolder, item: LogisItemBean) {
        helper.setText(R.id.tv_logis_date, item.date)
        helper.setText(R.id.tv_logis_status, item.logisticsInfo)

        val iv_logis_icon = helper.getView<ImageView>(R.id.iv_logis_icon)
        val view_logis_top = helper.getView<View>(R.id.view_logis_top)
        val view_logis_bottom = helper.getView<View>(R.id.view_logis_bottom)
        view_logis_top.visibility=View.VISIBLE
        view_logis_bottom.visibility=View.VISIBLE

        val position = helper.layoutPosition

        var imageSource = 0
        when (position) {
            (itemCount - 1) -> {//最后一个
                if (itemCount == 1) {
                    imageSource = R.drawable.ic_s_select

                    view_logis_top.visibility=View.INVISIBLE
                    view_logis_bottom.visibility=View.INVISIBLE
                } else {
                    imageSource = R.drawable.ic_s

                    view_logis_bottom.visibility=View.INVISIBLE
                }
            }
            0 -> {//第一个
                imageSource = R.drawable.ic_none_select

                view_logis_top.visibility=View.INVISIBLE
            }
            else -> {//其他
                imageSource = R.drawable.ic_none
            }
        }
        if (imageSource != 0) {
            helper.setImageResource(R.id.iv_logis_icon, imageSource)
        }
    }
}